﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace theguineasyndrome
{
    public class Score
    {
        private int numCollectedCarots;
        private int numCarots;
        private double beginTime;
        private double currentTime;
        private int totalScore;
        private SpriteFont font;
        private Texture2D carotTexture;

        public Score(double beginTime, SpriteFont font, Texture2D carotTexture, int numCarots)
        {
            this.font = font;
            this.carotTexture = carotTexture;
            this.beginTime = beginTime;
            this.numCarots = numCarots;
            numCollectedCarots = 0;
            numCarots = 0;
            totalScore = 0;
        }

        public Score()
        {
            numCollectedCarots = 0;
            numCarots = 0;
            totalScore = 0;
        }

        public void addCarot()
        {
            numCollectedCarots++;
        }

        public void Update(GameTime gameTime)
        {
            currentTime = gameTime.TotalGameTime.TotalMilliseconds;
            totalScore = (int)(1000 * numCollectedCarots * Math.Exp(-(currentTime - beginTime) / 300000));
        }

        public void Draw(SpriteBatch spriteBatch, Camera camera)
        {
            Color numCarotsColor = Color.DarkOrange;

            if (numCollectedCarots == numCarots)
                numCarotsColor = Color.Green;

            string strNumCarots = "" + numCollectedCarots + "/" + numCarots;

            Vector2 numCarotsSize = font.MeasureString(strNumCarots);
            spriteBatch.DrawString(font, strNumCarots, new Vector2(camera.Width - numCarotsSize.X - 15, 35), numCarotsColor);

            spriteBatch.Draw(carotTexture, new Vector2(camera.Width - 125, 10), Color.White);

            string strScore = "" + TotalScore;
            Vector2 scoreSize = font.MeasureString(strScore);
            spriteBatch.DrawString(font, strScore, new Vector2(camera.Width - scoreSize.X - 145, 35), Color.Black);
        }

        public int ElapsedTime
        {
            get { return (int)((currentTime - beginTime) / 1000f); }
        }

        public int NumCollectedCarots
        {
            get { return numCollectedCarots; }
            set { numCollectedCarots = value; }
        }

        public int NumCarots
        {
            get { return numCarots; }
            set { numCarots = value; }
        }

        public int TotalScore
        {
            get { return totalScore; }
            set { totalScore = value; }
        }
    }
}
